﻿using SqlSugar;
using Furion;
namespace AllServer.Core;

/// <summary>
/// SqlSugar归因仓储
/// </summary>
/// <typeparam name="T"></typeparam>
public class SqlSugarRepository<T> : SimpleClient<T> where T : class, new()
{
    private readonly SqlSugarScope sqlSugarScope;

    /// <summary>
    /// 非web请求建议传入sugarClient实例，web请求自动获取作用域的实例
    /// </summary>
    /// <param name="dbTypeEnum">默认库</param>
    /// <param name="client"></param>
    public SqlSugarRepository(AiCenterDbTypeEnum dbTypeEnum = AiCenterDbTypeEnum.GuiYinDB, ISqlSugarClient client = default)
    {
        sqlSugarScope = (client ?? App.GetService<ISqlSugarClient>()) as SqlSugarScope;
        Context = GetDB(dbTypeEnum);
    }

    /// <summary>
    /// 获取链接DB
    /// </summary>
    /// <param name="dbTypeEnum"></param>
    /// <returns></returns>
    protected ISqlSugarClient GetDB(AiCenterDbTypeEnum dbTypeEnum)
    {
        return sqlSugarScope.GetConnection(dbTypeEnum.ToString());
    }
}

/// <summary>
/// 数据库枚举
/// </summary>
public enum AiCenterDbTypeEnum
{
    /// <summary>
    /// AiNlpService库
    /// </summary>
    GuiYinDB = 0
}
